package com.qianyitian.hope2.analyzer.controller;

import com.alibaba.fastjson.JSON;
import com.qianyitian.hope2.analyzer.analyzer.EStockAnalyzer;
import com.qianyitian.hope2.analyzer.analyzer.IStockAnalyzer;
import com.qianyitian.hope2.analyzer.analyzer.StockAnalyzerFacotry;
import com.qianyitian.hope2.analyzer.config.Constant;
import com.qianyitian.hope2.analyzer.model.AnalyzeResult;
import com.qianyitian.hope2.analyzer.model.SymbolList;
import com.qianyitian.hope2.analyzer.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
public class WatchlistController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    WatchlistService watchlistService;

    public WatchlistController() {
    }

    @RequestMapping(value = "/watchlist/add/{code}", method = RequestMethod.GET)
    public String addWatch(@PathVariable String code) {
         watchlistService.add(code);
         return "ok";
    }
    @RequestMapping(value = "/watchlist/status/{code}", method = RequestMethod.GET)
    public String checkWatch(@PathVariable String code) {
        boolean ok =watchlistService.check(code);
        Map map=new HashMap();
        map.put("watched",ok);
        return JSON.toJSONString(map);
    }

    @CrossOrigin
    @RequestMapping(value = "/watchlist/delete/{code}", method = RequestMethod.GET)
    public String deleteWatch(@PathVariable String code) {
        watchlistService.delete(code);
        return "ok";
    }

    @CrossOrigin
    @RequestMapping(value = "/watchlist", method = RequestMethod.GET)
    public String getWatchlist() {
        return watchlistService.getWatchlist();
    }




}
